import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author: zlz
 * @date: 2021/9/12 9:34
 * @description:
 * @since: JDK1.8
 */
public class BioDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9000);
        while (true) {
            System.out.println("等待连接。。。");
            Socket clientSocket = serverSocket.accept();
            System.out.println("有客户端连接了");
            handle(clientSocket);
        }
    }

    private static void handle(Socket clientSocket) throws IOException {
        byte[] bytes = new byte[1024];
        System.out.println("准备接收数据。。。");
        int read = clientSocket.getInputStream().read(bytes);
        System.out.println("read 完毕");
        if (read != -1) {
            System.out.println("接收到客户端的数据:" + new String(bytes, 0, read));
        }
    }
}
